package com.demo.controller;



import com.demo.annotation.GlobalInterceptor;

import com.demo.annotation.VerifyParam;
import com.demo.entity.constants.Constants;
import com.demo.entity.po.CounselorInfo;
import com.demo.entity.query.CounselorInfoQuery;


import com.demo.entity.vo.ResponseVO;


import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import com.demo.service.CounselorInfoService;


@RestController
@RequestMapping("/counselor")
public class CounselorInfoController extends ABaseController {

	@Resource
	private CounselorInfoService counselorInfoService;



	/**
	 * 获取心理咨询师
	 */
	@RequestMapping("/loadCounselorList4User")
	@GlobalInterceptor(checkLogin = false)
	public ResponseVO loadCounselorList4User(CounselorInfoQuery query) {
		query.setOrderBy("update_time");
		query.setStatus(Constants.ONE);
		return getSuccessResponseVO(counselorInfoService.findListByPage(query));

	}


	/**
	 * 管理员查询咨询师
	 * @param query
	 * @return
	 */
	@RequestMapping("/loadCounselorList4Admin")
	@GlobalInterceptor(checkAdmin = true)
	public ResponseVO loadCounselorList4Admin(CounselorInfoQuery query) {
		query.setOrderBy("update_time");
		return getSuccessResponseVO(counselorInfoService.findListByPage(query));
	}


	/**
	 * 根据用户id
	 * @param userId
	 * @return
	 */
	@RequestMapping("/loadCounselorByUserId")
	@GlobalInterceptor(checkLogin = false)
	public ResponseVO loadCounselorByUserId(@VerifyParam(required = true)  Long userId) {
		CounselorInfo counselorInfo = counselorInfoService.getCounselorInfoByUserId(userId);
		return getSuccessResponseVO(counselorInfo);
	}

	/**
	 * 根据用户id 获取咨询师信息
	 * @param counselorId
	 * @return
	 */
	@RequestMapping("/loadCounselorByCounselorId")
	@GlobalInterceptor(checkLogin = false)
	public ResponseVO loadCounselor(@VerifyParam(required = true)  Long counselorId) {
		CounselorInfo counselorInfo = counselorInfoService.getCounselorInfoByCounselorId(counselorId);
		return getSuccessResponseVO(counselorInfo);
	}


	/**
	 * 保存咨询师信息
	 */
	@RequestMapping("/saveCounselor")
	@GlobalInterceptor(checkAdmin = true)
	public ResponseVO saveCounselor(CounselorInfo counselorInfo) {
		counselorInfoService.saveInfo(counselorInfo);
		return getSuccessResponseVO(null);
	}

	/**
	 * 撤销心理咨询师
	 * @param counselorId
	 * @return
	 */
	@RequestMapping("/updateStatus")
	@GlobalInterceptor(checkAdmin = true)
	public ResponseVO saveCounselor(@VerifyParam(required = true)  Long counselorId,
									@VerifyParam(required = true)  Integer status) {
		counselorInfoService.updateStatus(counselorId,status);
		return getSuccessResponseVO(null);
	}

	/**
	 * 删除信息
	 * @param counselorId
	 * @return
	 */
	@RequestMapping("/delInfo")
	@GlobalInterceptor(checkAdmin = true)
	public ResponseVO delInfo(@VerifyParam(required = true)  Long counselorId) {
		counselorInfoService.deleteCounselorInfoByCounselorId(counselorId);
		return getSuccessResponseVO(null);
	}


}